import { err } from "./logger.js";
export default function (packageName, index = 0) {
    return fetch(
        "https://ofcncog2cu-2.algolianet.com/1/indexes/npm-search/query?x-algolia-agent=Algolia%20for%20JavaScript%20(3.33.0)%3B%20Browser%20(lite)&x-algolia-application-id=OFCNCOG2CU&x-algolia-api-key=f54e21fa3a2a0160595bb058179bfb1e",
        {
            headers: {
                "content-type": "application/x-www-form-urlencoded",
            },
            body: `{\"params\":\"query= ${packageName}&page=${index}&hitsPerPage=10&attributesToHighlight=%5B%5D&attributesToRetrieve=%5B%22deprecated%22%2C%22description%22%2C%22githubRepo%22%2C%22homepage%22%2C%22keywords%22%2C%22license%22%2C%22name%22%2C%22owner%22%2C%22version%22%5D&analyticsTags=%5B%22jsdelivr%22%5D\"}`,
            method: "POST",
        }
    )
        .then((res) => res.json())
        .then(({ hits }) => {
            console.group("➡ searching... ", packageName);
            console.table(
                hits.map(({ name, version, description }) => ({
                    name,
                    version,
                    description,
                }))
            );
            console.groupEnd("➡ searching... ", packageName);
        })
        .catch(err("search"));
}
